#include<iostream>
using namespace std;
int T,n,a[200001],ans;
void dfs(int x,int s,int pr,int pb){
    if(x>n){ans=max(ans,s);return;}
    dfs(x+1,s+(a[pr]==a[x]?a[pr]:0),x,pb);
    dfs(x+1,s+(a[pb]==a[x]?a[pb]:0),pr,x);
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>T;
	while(T--){
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        ans=0;
        dfs(2,0,1,0);
        cout<<ans<<'\n';
	}
	return 0;
}
